package cxy.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
public class MyFirstMvcController {
    @RequestMapping("/hello.do")
    public String hello(){
        int i=1/0;
        System.out.println("入门程序");
        return "hello";
     }


    @RequestMapping("/hello2.do")
    public ModelAndView hello2(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("dashacha",new String("dashacha"));

        List<String> list = new ArrayList<>();
        list.add("小傻叉");
        list.add("中号傻叉");
        list.add("大号傻叉");
        mv.addObject("list",list);
        mv.setViewName("mv");
        return mv;
    }

    @RequestMapping("/hello3.do")
    public String ModelAndModelMapAndMapTest(ModelAndView mv, ModelMap mm, Map mp){

        mv.addObject("dashacha",new String("dashacha"));

        List<String> list = new ArrayList<>();
        list.add("小傻叉");
        list.add("中号傻叉");
        list.add("大号傻叉");
        mv.addObject("list",list);
//        mv.setViewName("mv");
        mm.addAttribute("dashacha2",new String("dashacha2"));
        mp.put("dashacha3",new String("dashacha3"));
        return "mv2";
    }



}
